<template>
  <div class="addSp">
    <div class="box">
      <div class="title">添加商品</div>
      <div class="inp">
        <el-form ref="modelRef" :rules="rules" :model="tableModel">
          <el-form-item prop="goods_name" label="商品名称">
            <el-input
              v-model="tableModel.goods_name"
              placeholder="请输入商品名称"
              size="default"
            ></el-input>
          </el-form-item>
          <el-form-item prop="goods_cat" label="1,2,3">
            <el-input v-model="tableModel.goods_cat" placeholder="1,2,3" size="default"></el-input>
          </el-form-item>
          <el-form-item prop="goods_price" label="商品价格">
            <el-input
              v-model="tableModel.goods_price"
              placeholder="请输入商品价格"
              size="default"
            ></el-input>
          </el-form-item>
          <el-form-item prop="goods_number" label="商品数量">
            <el-input
              v-model="tableModel.goods_number"
              placeholder="请输入商品数量"
              size="default"
            ></el-input>
          </el-form-item>
          <el-form-item prop="goods_weight" label="商品重量">
            <el-input
              v-model="tableModel.goods_weight"
              placeholder="请输入商品重量"
              size="default"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="but">
        <el-button>取消</el-button>
        <el-button type="primary" @click="add">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { addSp } from '@/api/addSp'
const tableModel = ref({
  goods_name: '水电费第三方离开时间塑料袋咖啡机都说了会计法到拉萨数量肯德基飞流式快递费较大卢萨卡',
  goods_cat: '1',
  goods_price: 99.99,
  goods_number: 666,
  goods_weight: 3,
})
const rules = reactive({
  goods_name: [
    { required: true, message: '请输入活动名称', trigger: 'blur' },
    { min: 3, max: 50, message: '长度在 3 到 5 个字符', trigger: 'blur' },
  ],
  goods_cat: [
    { required: true, message: '请输入活动名称', trigger: 'blur' },
    { min: 3, max: 50, message: '长度在 3 到 5 个字符', trigger: 'blur' },
  ],
  goods_price: [
    { required: true, message: '请输入活动名称', trigger: 'blur' },
    { min: 3, max: 50, message: '长度在 3 到 5 个字符', trigger: 'blur' },
  ],
  goods_number: [
    { required: true, message: '请输入活动名称', trigger: 'blur' },
    { min: 3, max: 50, message: '长度在 3 到 5 个字符', trigger: 'blur' },
  ],
  goods_weight: [
    { required: true, message: '请输入活动名称', trigger: 'blur' },
    { min: 3, max: 50, message: '长度在 3 到 5 个字符', trigger: 'blur' },
  ],
})
const add = async () => {
  try {
    await addSp({ ...tableModel.value })
  } catch (err) {
    console.log('err', err)
  }
}
</script>

<style scoped lang="scss">
.box {
  background: #fff;
  padding: 20px;
}
</style>
